package main

import (
	"gitee.com/Frank098/container-management/model"
	"gitee.com/Frank098/container-management/router"
	"gitee.com/Frank098/container-management/service"
	"gitee.com/Frank098/container-management/utils/log"
	"github.com/caarlos0/env/v6"
	"os"
)

func main() {
	log.Info("开始启动程序")
	cfg := &model.Config{}
	err := env.Parse(cfg)
	if err != nil {
		log.Errorf("%+v\n", err)
		return
	}
	log.Info("env配置加载成功")
	log.InfoJson(cfg)
	if os.Getenv("mode") == "debug" {
		cfg.IsDebug = true
	}

	// 初始化k8s client
	service.K8s.KubernetesInit(cfg.KubeConfig)

	r := router.Register()
	go func() {
		err = r.Run(cfg.ListenPort)
		if err != nil {
			//panic(err)
			log.Errorf("%+v\n", err)
		}
	}()

	//利用chan读取不到数据就一直阻塞来保证主协程不退出
	done := make(chan int)
	<-done
}
